package com.grts.mall.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.grts.mall.common.CommonResult;
import com.grts.mall.pojo.Cart;
import com.grts.mall.pojo.vo.CartResultVo;
import com.grts.mall.service.CartService;

@RestController
public class CartController {
	@Autowired
	private CartService cartService;
	
	@RequestMapping("/product/cart")
	public CommonResult cart(@RequestBody Cart vo) {
		this.cartService.add(vo);
		return CommonResult.success();
	}
	
	@RequestMapping("/product/findall")
	public CommonResult findall(Long uid) {
		List<CartResultVo> carts = this.cartService.findByCart(uid);
		return CommonResult.success(carts);
	}
	
	@RequestMapping("/product/updata")
	public CommonResult updata(Cart cart) {
		this.cartService.updata(cart);
		return CommonResult.success();
	}
	
	@RequestMapping("/product/del")
	public CommonResult del(Cart cart) {
		Long del = this.cartService.del(cart);
		if (del==0) {
			return CommonResult.error();
		}else {
			return CommonResult.success();
		}
	}
}
